package com.rxyb.security.gate.controller.reactive;

import cn.rxyb.core.respone.R;
import com.rxyb.security.gate.model.UpdateSysUserReq;
import com.rxyb.security.gate.model.UpdateSysUserRsp;
import com.rxyb.security.gate.model.UserListReq;
import com.rxyb.security.gate.model.UserListRsp;
import com.rxyb.security.gate.model.common.AddSysUserReq;
import com.rxyb.security.gate.model.common.AddSysUserRsp;
import com.rxyb.security.service.SysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YJH
 * @version 1.0
 * @description 用户信息
 * @date 2020/7/12 15:56
 */
@RestController
@RequestMapping(value = "user")
public class UserReactiveController {

    private final SysUserService sysUserServiceImpl;

    public UserReactiveController(SysUserService sysUserServiceImpl) {
        this.sysUserServiceImpl = sysUserServiceImpl;
    }


    /**
     * 增加用户
     *
     * @param req 请求参数
     * @param rsp 响应参数
     * @return
     */
    @PostMapping(value = "addSysUser", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<AddSysUserRsp> addSysUser(@RequestBody AddSysUserReq req) {
        AddSysUserRsp rsp = new AddSysUserRsp();
        BeanUtils.copyProperties(req, rsp);
        return sysUserServiceImpl.addSysUser(req, rsp);
    }


    /**
     * 更新用户信息
     *
     * @param req 请求参数
     * @param rsp 响应参数
     * @return
     */
    @PostMapping(value = "updateSysUser", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<UpdateSysUserRsp> updateSysUser(@RequestBody UpdateSysUserReq req) {
        UpdateSysUserRsp rsp = new UpdateSysUserRsp();
        BeanUtils.copyProperties(req, rsp);
        return sysUserServiceImpl.updateSysUser(req, rsp);
    }


    /**
     * 用户查询信息
     *
     * @param req 请求参数
     * @param rsp 响应参数
     * @return
     */
    @PostMapping(value = "userList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<UserListRsp> userList(@RequestBody UserListReq req) {
        UserListRsp rsp = new UserListRsp();
        BeanUtils.copyProperties(req, rsp);
        return sysUserServiceImpl.userList(req, rsp);
    }

}
